package cn.zwx.base.exception;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.enums.ResponseCodeEnum;
import cn.zwx.base.utils.json.JsonUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author zhangwenxue
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BizWrapException extends Exception{

    private int code;
    private String msg;

    public <T> BizWrapException(ResponseEntity<T> responseEntity) {
        super("\n code:"+responseEntity.getCode()+"\n message:"+ JsonUtils.toJsonString(responseEntity.getMsg()));
        this.code = responseEntity.getCode();
        this.msg = responseEntity.getMsg();
    }

    public BizWrapException(int code , String message) {
        super("\n code:"+code+"\n message:"+JsonUtils.toJsonString(message));
        this.code = code;
        this.msg = message;
    }


    public BizWrapException(ResponseCodeEnum responseCodeEnum) {
        super("\n code:"+responseCodeEnum.getCode()+"\n message:"+JsonUtils.toJsonString(responseCodeEnum.getMsg()));
        this.code = responseCodeEnum.getCode();
        this.msg = responseCodeEnum.getMsg();
    }
}
